package com.noble.meether.ui.vip.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.noble.meether.R;
import com.noble.library.widget.RecyclerView.base.BaseRecyclerViewAdapter;
import com.noble.library.widget.RecyclerView.base.BaseRecyclerViewHolder;
import com.noble.meether.ui.vip.bean.Vip;

/**
 * Vip充值列表
 */
public class VipAdapter extends BaseRecyclerViewAdapter<Vip> {
    private Context mContext;
    private int position;     // 选中item

    public VipAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public int[] getItemLayouts() {
        return new int[]{R.layout.item_vip_item};
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return super.onCreateViewHolder(parent, viewType);
    }

    @Override
    public void onBindRecycleViewHolder(BaseRecyclerViewHolder viewHolder, int position) {
        final MyViewHolder vh = new MyViewHolder(viewHolder);
        final Vip info = getItem(position);
        vh.tv_time.setText(info.getDescribe());
        vh.tv_price.setText("￥" + info.getAmount());
        vh.tv_discount.setText("￥" + info.getDiscount());
        vh.tv_discount.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);

        vh.rl_item.setBackgroundResource(R.drawable.btn_fill_gold_bg);
        if (this.position == position) {
            vh.rl_item.setBackgroundResource(R.drawable.rectangle_stroke5);
        }
    }

    public void setSelected(int position) {
        this.position = position;
    }

    @Override
    public int getRecycleViewItemType(int position) {
        return 0;
    }

    class MyViewHolder {
        RelativeLayout rl_item;
        TextView tv_time, tv_price, tv_discount;

        public MyViewHolder(BaseRecyclerViewHolder convertView) {
            initView(convertView);
        }

        private void initView(BaseRecyclerViewHolder convertView) {
            rl_item = convertView.findViewById(R.id.rl_item);
            tv_time = convertView.findViewById(R.id.tv_time);
            tv_price = convertView.findViewById(R.id.tv_price);
            tv_discount = convertView.findViewById(R.id.tv_discount);
        }
    }
}